<?php

namespace app\admin\controller;
use app\admin\services\AmindmanualService;
use think\App;
use think\Request;


/**
 * @后台手册管理
 */
class Adminmanual extends Authent
{
    protected $manualService;
    public function __construct(Request $request, App $app)
    {
        parent::__construct($request, $app);
        $this->manualService = new AmindmanualService();
        
        global $authstate;
        if($authstate){
            if(isset($authstate['status']) && $authstate['status'] !=0 ){
                echo json_encode($authstate); die;
            }
        }
        
        
    }
    
    /**
     * @手册查看
     */
    public function index1(){
        $groupModel = new \app\admin\services\AdminManuakGroupService();
        $group = $groupModel->selectParentList();
        $this->assign('group',$group);
        $id = input('get.id');
        if(empty($id)){
            if(!empty($group[0]['id'])){
                $id=$group[0]['id'];
            }else{
                echo '无数据权限！！';exit();
            }
        }
        
        
        $this->assign('id',$id);
        
        $data = $groupModel->selectListShowData($id,[]);
        foreach($data as $k=>$v){
            $data[$k]['manual'] = $v['manual']->toArray();
        }
        $this->assign('data',$data);
     
        return view('index1');
    }
    
    
    
    /**
     * @关键字查询数据
     */
    public function searchData(){
        $data = $this->manualService->selectLikeList();
        return json($data);
    }
    
    /**
     * @获取详细内容
     */
    public function getDataDetails(){
        $find = $this->manualService->getDataById();
        $this->assign('data',$find);
        return view('right');
    }
    
    public function index()
    {
        $data = $this->getGroup();
       
        $this->assign('data',$data);
  
        $this->assign('fpid',$data[0]['id']);
       
        $this->assign('fid',$data[0]['child'][0]['id']);
        return view('index');
    }
    
    /**
     * @获取分类
     */
    public function getGroup(){
        $mg = new \app\admin\services\AdminManuakGroupService();
        $data = $mg->getParentData([['status','neq',-1],['id','in',$_SESSION['admin']['manual']]]);
        
        if(empty($data[0])){
            echo '无数据权限！！';exit();
        }
        
        foreach($data as $k=>$v){
            $data[$k]['child'] = $mg->getParentData([['status','neq',-1],['pid','eq',$v['id']]]);
        }
        
        return $data;
    }
    
    /**
     * @添加手册内容
     */
    public function add(){
        $data = $this->getGroup();
        $this->assign('data',$data);
        return view('add');
    }
    
    /**
     * @修改手册内容
     */
    public function edit(){
        $mg = new \app\admin\services\ManualGroupService();
        $data = $this->getGroup();
        $this->assign('data',$data);
        
        $find = $this->manualService->getDataById();
        $this->assign('find',$find);
        
        return view('edit');
    }
     /**
     * @修改状态
     */
    public function editStatus(){
        $data = $this->manualService->editStatus();
        return $data;
    }
    /**
     * @保存数据
     */
    public function saveData(){
        $data = $this->manualService->saveData();
        return $data;
    }
    
    /**
     * @获取数据
     * @param int $pageIndex 当前页码
     * @param int $pageSize 每页条数
     * @param string $keyword 关键字查询
     * @param int $groupId 分类ID
     */
    public function getList(){
        $data = $this->manualService->getListByPage();
        return json($data);
    }
    
    /**
     * @删除
     */
    public function del(){
        $data = $this->manualService->del();
        return $data;
    }
    
    /**
     * @param 上传图片
     */
    public function ajaxUpload(){
        $data = $this->manualService->ajaxUpload();
        return json($data);
    }

}